package cn.kgc.kgckafkaclient.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author geQiang
 * @version 1.0
 * @date 2019/4/16
 * @description cn.kgc.kgckafkaclient.controller
 */
@RestController
public class KafkaController {
    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @RequestMapping("/sendToKafka")
    public String sendToKafka() {
        for (int i = 0; i < 10; i++) {
            //String topic, K key, V data
            kafkaTemplate.send("user_consumer", "dm", "hello,user_consumer,comes from kafka!--->" + i);
        }
        return "消息已经发送到kafka";
    }
}
